#include "wqLinkItem.h"

wqLinkItem::wqLinkItem( const LInfo& lf, QGraphicsItem* parent /*= NULL*/ )
: QGraphicsLineItem(parent)
{
	setZValue(1);

	sourcePoint = lf.spos;
	destPoint = lf.dpos;

	setLine(QLineF(mapFromScene(sourcePoint), mapFromScene(destPoint)));

	QVariant var;
	var.setValue(lf);

	setData(1, var);
	setData(999, 3);
}

//void wqLinkItem::Adjust()
//{
//	prepareGeometryChange();
//}

//QRectF wqLinkItem::boundingRect() const
//{
//	return QRectF(sourcePoint, QSizeF(destPoint.x() - sourcePoint.x(),
//		destPoint.y() - sourcePoint.y()))
//		.normalized();
//}

void wqLinkItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* item, QWidget* wid)
{
	painter->save();
	
	painter->setPen(QPen(Qt::green,5));

	painter->drawLine(line());

	//painter->setPen(QPen(Qt::red,1));
	//painter->drawRect(boundingRect());

	painter->restore();
}

void wqLinkItem::AdjustSourcePos(const QPointF& pos)
{
	sourcePoint = pos;
	setLine(QLineF(mapFromScene(sourcePoint), mapFromScene(destPoint)));
}

void wqLinkItem::AdjustDestPos(const QPointF& pos)
{
	destPoint = pos;
	setLine(QLineF(mapFromScene(sourcePoint), mapFromScene(destPoint)));
}

void wqLinkItem::contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
{

}